package com.jason.bookworm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jason.bookworm.dao.mapper.FeedbackMapper;
import com.jason.bookworm.dao.pojo.Feedback;
import com.jason.bookworm.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper,Feedback> implements FeedbackService {
    @Autowired
    FeedbackMapper feedbackMapper;

    @Override
    public List<Feedback> getAllFeedback() {
        return feedbackMapper.selectList(null);
    }

    @Override
    public List<Feedback> getAllFeedback(String username) {
        QueryWrapper<Feedback>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("f_username",username)
                .ne("f_status","2");
        return feedbackMapper.selectList(queryWrapper);
    }

    @Override
    public Feedback getOneFeedback(String feedbackId) {
        return feedbackMapper.selectById(feedbackId);
    }

    @Override
    public void answerOneFeedback(Feedback feedback) {
        feedback.setStatus("1");
        feedbackMapper.updateById(feedback);
    }

    @Override
    public void deleteOneFeedback(Feedback feedback) {
        feedback.setStatus("2");
        feedbackMapper.updateById(feedback);
    }
}
